﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace blackhouse.NemoBlog.Business.Model {
    public class StandardPostListModel : IPostListModel {

        #region Fields

        private int placeId;
        private NemoBlogPosts posts;

        #endregion

        #region Properties

        public int PlaceId {
            get {
                return this.placeId;
            }
            set {
                if (this.placeId != value) {
                    this.placeId = value;
                    this.posts = new NemoBlogPosts(this.placeId);
                }
            }
        }

        public int PostCountOnPage { get { return 10; } }

        private NemoBlogPosts Posts {
            get {
                if (this.posts == null)
                    throw new Exception("Lista postów jest niedostępna ponieważ nie ustawiono wartości dla PlaceId");
                return this.posts;
            }
        }

        #endregion

        #region Methods

        public NemoBlogPost[] GetLastPosts(int postCount, bool onlyPublished) {
            return this.Posts.GetLastPosts(postCount, onlyPublished);
        }

        public NemoBlogPost[] GetLastPosts(int lastPostId, int postCount, bool onlyPublished) {
            return this.Posts.GetLastPosts(lastPostId, postCount, onlyPublished);
        }

        public NemoBlogPost[] GetPostsByTag(NemoBlogTag tag, int postCount, bool onlyPublished) {
            return this.Posts.GetPostsByTag(tag.TagId, onlyPublished);
        }

        #endregion

    }
}
